﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPFPrism.Common.Models;
using WPFPrism.Extensions;

namespace WPFPrism.ViewModels
{
    public class SettingsViewModel : BindableBase
    {

        /// <summary>
        /// 导航命令
        /// </summary>
        public DelegateCommand<MenuBar> NavigateCommand { get; set; }

        /// <summary>
        /// 菜单集合
        /// </summary>
        private ObservableCollection<MenuBar> menuBars;

        /// <summary>
        /// 区域显示
        /// </summary>
        private readonly IRegionManager regionManager;

        /// <summary>
        /// 区域导航日志
        /// </summary>
        private IRegionNavigationJournal journal;

        /// <summary>
        /// 菜单集合的变化，加载的时候跟着变化
        /// </summary>
        /// 
        public SettingsViewModel(IRegionManager regionManager)
        {
            MenuBars = new ObservableCollection<MenuBar>();
            this.regionManager = regionManager;
            NavigateCommand = new DelegateCommand<MenuBar>(Navigate);
            CreateMenuBar();
        }
        public ObservableCollection<MenuBar> MenuBars
        {
            get { return menuBars; }
            set { menuBars = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// 导航集合
        /// </summary>
        /// <param name="obj"></param>
        private void Navigate(MenuBar obj)
        {
            if (obj == null || string.IsNullOrWhiteSpace(obj.NameSpace))
            {
                return;
            }
            regionManager.Regions[PrismManager.SettingViewRegionName].RequestNavigate(obj.NameSpace);


        }
        private void CreateMenuBar()
        {
            MenuBars.Add(new MenuBar() { Icon = "Palette", NameSpace = "SkinView", Title = "个性化" });
            MenuBars.Add(new MenuBar() { Icon = "Cog", NameSpace = "SystemConfigView", Title = "系统设置" });
            MenuBars.Add(new MenuBar() { Icon = "Information", NameSpace = "AboutView", Title = "关于" });
        }
    }
}
